package com.media.feignclient;

import com.base.model.R;
import com.media.model.Media;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;

import java.util.List;

/**
 * @Author: 小何
 * @Description: TODO
 * @DateTime: 2023/9/27 15:50
 **/
@Slf4j
public class MediaSearchClientFactory implements FallbackFactory<MediaSearchClient> {
    @Override
    public MediaSearchClient create(Throwable throwable) {
        return new MediaSearchClient() {
            @Override
            public R<String> deleteMediaByMediaId(String mediaId) {
                log.error("视频下架发生熔断,视频Id为{},熔断异常为:{}",mediaId,throwable.toString(),throwable);
                return R.error("视频下架服务熔断");
            }

            @Override
            public R<List<Media>> listMediaBySearchBox(String searchContext, Integer orderCode, Integer page, Integer category, Integer timeCode) {
                log.error("视频查询发生熔断,查询内容为{},排序码为:{},页码为:{},分类码为:{},时长码为{},熔断异常为:{}",searchContext,orderCode,page,category,timeCode,throwable.toString(),throwable);
                return R.error("视频查询服务熔断");
            }

            @Override
            public R<String> saveMedia(Media media) {
                log.error("es文档添加发生熔断，视频内容为:"+media.toString());
                return R.error("es文档添加异常");
            }


//            @Override
//            public R<String> test() {
//                return R.error("");
//            }
        };
    }
}
